package com.example.carefree_server.service.impl.i_loginImpl;

import com.example.carefree_server.entity.Department;
import com.example.carefree_server.entity.Student;
import com.example.carefree_server.mapper.m_loginMapper.LoginMapper;
import com.example.carefree_server.service.s_loginService.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;

    @Override
    public int findstudent(String sid, String spassword) {
        if (loginMapper.finduser(sid, spassword) == 1) {
            return 1;
        } else if (loginMapper.finddepartment(sid, spassword) == 1) {
            return 2;
        } else if (loginMapper.findemanage(sid, spassword) == 1) {
            return 3;
        } else {
            return 0;
        }
    }

    //    重置密码/密保
    @Override
    public int checkprotection(String id, String protection1) {
        System.out.println("LoginService/checkprotection这里：" + id + "," + protection1);
        if (loginMapper.scheckprotection(id, protection1) == 1) {
            return 1;
        } else if (loginMapper.dcheckprotection(id, protection1) == 1) {
            return 2;
        }
        return 0;

    }

    @Override
    public int changepassword(String id, String password) {
        System.out.println("LoginService/changepassword这里：" + id + "," + password);
        if (loginMapper.supdatepassword(id, password) == 1) {
            return 1;
        }
        if (loginMapper.dupdatepassword(id, password) == 1) {
            return 2;
        }
        return 0;

    }

    @Override
    public int changepasswordprotection(String id, String question1, String protection1) {
        System.out.println("LoginService/changepasswordprotection这里：" + id + "," + question1 + "," + protection1);
        if (loginMapper.supdatepasswordprotection(id, question1, protection1) == 1) {
            return 1;
        }
        if (loginMapper.dupdatepasswordprotection(id, question1, protection1) == 1) {
            return 2;
        }
        return 0;
    }

    @Override
    public int GetId(String id) {
        if (loginMapper.finduserId(id) == 1) {
            return 1;
        } else if (loginMapper.finddepartmentId(id) == 1) {
            return 2;
        } else {
            return 0;
        }
    }

    @Override
    public List<Student> getsquestion1(String id) {
        return loginMapper.selectsquestion1(id);
    }

    @Override
    public List<Department> getdquestion1(String id) {
        return loginMapper.selectdquestion1(id);
    }
}



